import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import ViteRestart from 'vite-plugin-restart'

export default defineConfig((mode) => {
  const env = loadEnv(mode, process.cwd())
  const name = env.VITE_APP_TITLE
  const port = env.VITE_APP_PORT
  return {
    plugins: [
      vue(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      }),
      ViteRestart()
    ],
    server: {
      port,
      open: true
    }
  }
})
